<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="/WEB-INF/tld/extend.tld" prefix="extend"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>乐盈培训网 - 查看课程</title>
		<link href="<extend:contextPath name="contextPath"/>/css/style.css" rel="stylesheet" type="text/css" />
		<script language="JavaScript" src="<extend:contextPath name="contextPath"/>/scripts/jquery.js"></script>
		<script language="JavaScript" src="<extend:contextPath name="contextPath"/>/scripts/common.js"></script>						
	</head>
	
	<script type="text/javascript">
		function getTeacherByCategory(category)
		{			
			//提交时 中文乱码问题
			//var post = "/qiyexuexi/admin/getTeacherByCategory.do?method=getTeacherByCategory&category=" + category + "&jsoncallback=?";
			var post = "<extend:contextPath name="contextPath"/>/admin/getTeacherByCategory.do?method=getTeacherByCategory&category=" + category;
			post = encodeURI(post);
  			post = encodeURI(post);
		
			//添加繁忙图片
			var  courseTeacherTR = document.getElementById("courseTeacherTR");
			var  td = document.createElement("td");
			var image = new Image();
			//image.id = "busy";
			image.src = "<extend:contextPath name="contextPath"/>/images/busy.gif";
			
			td.appendChild(image);
			courseTeacherTR.appendChild(td);
			
		
			$.getJSON(post,
				function(json) {
				
					var courseTeacher = document.getElementsByName("courseTeacher");
				
					courseTeacher[0].options.length = 0;				
					courseTeacher[0].options.add(new Option("--请选择--", ""));
					
					$.each(json, function(i){
						var down = json[i];
						for(var j = 0; j < down.length; j++) {
							courseTeacher[0].options.add(new Option(down[j].value, down[j].key));			
						}
						
						//移除 繁忙图片
						courseTeacherTR.removeChild(td);
					});
				}
			);		
		}
	</script>
	
<body>

	<div style="position:absolute; height:100%; width:1045px;">
		<jsp:include page="../header.jsp"></jsp:include>
			<table width="100%" border="0" cellpadding="0" cellspacing="0" style="font-size:12px;">
					<tr>
						<td height="25px">
							您现在的位置：<a href="<extend:contextPath name="contextPath"/>" class="normal_link">首页</a> >> 
							<a href="<extend:contextPath name="contextPath"/>/admin/goToAdmin.do" class="normal_link">admin</a> >> 查找课程
						</td>
					</tr>
			</table>
				
		<html:form action="/searchCourseProcess.do?method=searchCourse">
		<table width="100%" style="font-size:14px;">
			<tr>
				<td width="20%">课程名称:</td>
				<td><html:text property="courseTitle" /></td>
			</tr>
			<tr>
				<td>课程时间:</td>
				<td><html:text property="coursePeriod" /></td>
			</tr>
			<tr>
				<td>课程开始时间:</td>
				<td><html:text property="courseStartTimeAsStr"/></td>
			</tr>
			<tr>
				<td>课程结束时间:</td>
				<td><html:text property="courseEndTimeAsStr" /></td>
			</tr>			
			<tr>
				<td>课程价格:</td>
				<td><html:text property="coursePrice" /></td>
			</tr>
			<tr>
				<td>课程所在城市:</td>
				<td><html:text property="courseCity" /></td>
			</tr>
			<tr>
				<td>课程类别:</td>
				<td><html:select property="courseCategory" onmouseover="getCourseCategory('courseCategory') ;"
								 onchange="getTeacherByCategory(this.value);">
								 <html:option value="">--请选择--</html:option>
						</html:select>
				</td>
			</tr>
			<tr id="courseTeacherTR">
				<td>课程老师:</td>
				<td>
					<html:select property="courseTeacher">
						<html:option value="">--请选择--</html:option>
					</html:select>
				</td>
			</tr>
			<tr>
				<td colspan="2">
					<html:checkbox property="isHotCourse" value="Y">是否热门课程</html:checkbox>
					<html:checkbox property="isRecommendCourse" value="Y">是否推荐课程</html:checkbox>
					<html:checkbox property="isPublicCourse" value="Y">是否公开课程</html:checkbox>
				</td>
			</tr>
			<tr>
				<td>
					<html:submit>提交</html:submit>&nbsp;&nbsp;&nbsp;&nbsp;
				</td>
			</tr>
		</table>
	</html:form>
	
	<c:choose>
		<c:when test='${empty courseList}'>
			<c:if test='${courseList != null}'>
				没有找到符合记录。
			</c:if>
		</c:when>	
		<c:otherwise>
			<html:form action="/deleteCourse.do?method=deleteCourse" onsubmit="return confirm('确定删除记录吗？');">
			<table style="font-size:14px;">
				<tr>
					<td width="10"><input type="checkbox" name="masterCheckbox" onclick="toggleCheckboxes(form.deleteSelection, this.checked)"></td>
					<td width="10">No.</td>
					<td width="120">课程标题</td>
					<td width="120">课程类别</td>
					<td width="80">课程价格</td>
					<td width="120">课程开始时间</td>
					<td width="120">课程结束时间</td>
					<td width="11"></td>
					<td width="11"></td>
				</tr>
				
				<c:forEach var="course" items="${courseList}" varStatus="status">
					<tr>
						<td height="20">
							<html:multibox property="deleteSelection" 
								onclick="toggleMasterCheckbox(masterCheckbox, this.checked, deleteSelection)">
								<c:out value="${course.courseId}" />|<c:out value='${course.version}' />
							</html:multibox>
						</td>						
						<td><c:out value="${status.index + 1}" /></td>
						<td><c:out value="${course.courseTitle}" /></td>
						<td><c:out value="${course.courseCategory}" /></td>
						<td><c:out value="${course.coursePrice}" /></td>
						<td><c:out value="${course.courseStartTimeAsStr}" /></td>
						<td><c:out value="${course.courseEndTimeAsStr}" /></td>
						<td id="sc_edit" align="center"><a class="href_edit" title="编辑" href="#" 
								onclick="javascript:viewEditCourse('<c:out value='${course.courseId}' />')">&nbsp;</a>
						</td>							
						<td id="sc_delete" align="center"><a class="href_delete" title="删除" href="#" 
								onclick="javascript:deleteCourse('<c:out value='${course.courseId}' />','<c:out value='${course.version}' />')">&nbsp;</a>
						</td>						
					</tr>					
				</c:forEach>
				<tr>
					<td colspan="10">
						<html:submit>删除</html:submit>
					</td>
				</tr>
				
				<tr>
					<td colspan="10">
					<extend:paginationNav currentPage="${paginationSortOrderData.currentPage}" pageSize="${paginationSortOrderData.pageSize}" totalCount="${totalCount}"/>						
					</td> 
				</tr>
				
			</table>
			
				<html:hidden property="courseTitle"/>
				<html:hidden property="coursePeriod"/>
				<html:hidden property="courseStartTimeAsStr"/>
				<html:hidden property="courseEndTimeAsStr"/>
				<html:hidden property="coursePrice"/>
				<html:hidden property="courseCity"/>
				<html:hidden property="courseCategory"/>
				<html:hidden property="courseTeacher"/>
				<html:hidden property="isHotCourse"/>
				<html:hidden property="isRecommendCourse"/>
				<html:hidden property="isPublicCourse"/>
				
				
				<script>
					function resubmit(i)
					{
						document.forms[1].action="<extend:contextPath name="contextPath"/>/admin/searchCourseProcess.do?method=searchCourse&page=" + i;
						document.forms[1].method="post";
						document.forms[1].submit();	
					}
					function viewEditCourse(courseId)
					{
						window.location = "<extend:contextPath name="contextPath"/>/admin/viewEditCourse.do?method=viewEditCourse&courseId=" + courseId;
					}
					function deleteCourse(courseId, version)
					{
						if(confirm("确定要删除该条记录吗？"))
						{						
							document.forms[1].action="<extend:contextPath name="contextPath"/>/admin/deleteCourse.do?method=deleteCourse&courseId="+courseId+"&version="+version;
							document.forms[1].method="post";
							document.forms[1].submit();	
						}
					}
				</script>
				
			</html:form>
		</c:otherwise>
	</c:choose>
	
	<script>
		var categoryValue = "<c:out value='${courseCategory}' />";
		var teacherValue = "<c:out value='${courseTeacher}' />";
		if (categoryValue != null && categoryValue != "") 
		{
			getCourseCategory('courseCategory');
			var categorySelect = document.getElementsByName("courseCategory");
			
			for(var i = 0; i < categorySelect[0].options.length; i++)
			{				
				var temp = 	categorySelect[0][i].value;
				alert(temp);
				if(categoryValue == temp)
				{
					categorySelect[0][i].selected = true;

					getTeacherByCategory(categoryValue);
					
					break;
				}
			}	

			if(teacherValue != null && teacherValue != "")
			{
				var teacherSelect = document.getElementsByName("courseTeacher");
				for (var i = 0; i < teacherSelect[0].options.length; i++)
				{
					if(teacherSelect[0].options[i].value == teacherValue)
					{
						teacherSelect[0].options[i].selected = true;
						break;
					}
				}
			}		
		} 
	</script>
	
	</div>	
</body>
</html>